package com.doubi.controller.work;

import com.doubi.common.aspectj.annotation.SysLog;
import com.doubi.constants.SystemConstants;
import com.doubi.model.sys.TAdver;
import com.doubi.model.sys.THelpCenter;
import com.doubi.modelvo.sys.THelpCenterVo;
import com.doubi.service.ApiHelpCenterService;
import com.doubi.service.HelpCenterService;
import com.doubi.utils.DataUtil;
import com.doubi.vo.AppModel;
import com.doubi.vo.AppUiModel;
import com.doubi.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("helpCenter")
public class HelpCenterController {
    @Autowired
    private HelpCenterService helpCenterService;


    @RequiresPermissions("helpCenter:view")
    @GetMapping("view")
    public String view(Integer type,Model model){
        model.addAttribute("type",type);
        return "web/helpCenter/view";
    }

    @RequiresPermissions("helpCenter:page")
    @PostMapping("page")
    @ResponseBody
    public PageVo<THelpCenter> getPage(PageVo<THelpCenter> page, THelpCenter helpCenter){
        return helpCenterService.getPage(page,helpCenter);
    }

    @SysLog(title = "删除帮助中心")
    @RequiresPermissions("helpCenter:del")
    @PostMapping("del")
    @ResponseBody
    public AppModel delBean(String oid){
        return helpCenterService.delBean(oid);
    }

    @PostMapping("getBean")
    @ResponseBody
    public AppModel getBean(String oid){
        return AppModel.success(helpCenterService.getById(oid));
    }


    @RequiresPermissions("helpCenter:edit")
    @GetMapping("edit")
    public String edit(THelpCenter helpCenter, Model model,Integer type) {
        model.addAttribute("type", type);
        if (DataUtil.isNotEmpty(helpCenter.getOid())) {
            helpCenter = helpCenterService.getById(helpCenter.getOid());
            model.addAttribute("type", helpCenter.getType());
        }
        model.addAttribute("bean", helpCenter);
        return "web/helpCenter/edit";
    }

    @RequiresPermissions("helpCenter:edit")
    @GetMapping("editOne")
    public String editOne(String oid,Model model) {
        model.addAttribute("oid",oid);
        return "web/helpCenter/editOne";
    }


    @SysLog(title = "帮助中心修改添加")
    @RequiresPermissions("helpCenter:saveOrUpdateBean")
    @PostMapping("saveOrUpdateBean")
    @ResponseBody
    public AppModel saveOrUpdateBean(THelpCenter helpCenter){
        return helpCenterService.saveOrUpdateBean(helpCenter);
    }

}
